<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>轨迹回放</title>
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"/>
    <style>
        html, body, #container {
            height: 100%;
            width: 100%;
        }

        .input-card .btn{
            margin-right: 1.2rem;
            width: 9rem;
        }

        .input-card .btn:last-child{
            margin-right: 0;
        }
    </style>
</head>
<body>
<div id="container"></div>
<div class="input-card">
    <h4>轨迹回放控制</h4>
    <div class="input-item">
        <input type="button" class="btn" value="开始动画" id="start" onclick="startAnimation()"/>
        <input type="button" class="btn" value="暂停动画" id="pause" onclick="pauseAnimation()"/>
    </div>
    <div class="input-item">
        <input type="button" class="btn" value="继续动画" id="resume" onclick="resumeAnimation()"/>
        <input type="button" class="btn" value="停止动画" id="stop" onclick="stopAnimation()"/>
    </div>
</div>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=91c1aeee49ce767cb2c2d637607ac8ca"></script>
<script src="../../js/application.js"></script>
<script type="text/javascript" src="../../js/jquery-3.3.1.js" ></script>
<script type="text/javascript" src="../../layui/layui.all.js" charset="utf-8"></script>
<script type="text/javascript" src="../../js/mapRoute.js" charset="utf-8"></script>
<script>
    /* var  lineArr = [[103.00444,25.239288],
        [103.005014,25.239269],
        [103.005744,25.240705],
        [103.006259,25.240453],
        [103.006468,25.24039],
        [103.006736,25.240356],
        [103.006972,25.240409],
        [103.007197,25.240516],
        [103.008362,25.242025],
        [103.008308,25.242466],
        [103.008024,25.242787],
        [103.007112,25.243151]]; */
		
	/* AMap.GraspRoad();
	driving(path:OriginPath,GraspRoadCallback:function(err:Object,result:GraspedPath)); */
	
    var map = new AMap.Map("container", {
        resizeEnable: true,
        center: start,
        zoom: 11
    });

    marker = new AMap.Marker({
        map: map,
        position: start,
        icon: "https://webapi.amap.com/images/car.png",
        offset: new AMap.Pixel(-26, -13),
        autoRotation: true,
        angle:-90,
    });

    // 绘制轨迹
    var polyline = new AMap.Polyline({
        map: map,
        path: lineArr,
        showDir:true,
        strokeColor: "#28F",  //线颜色
        // strokeOpacity: 1,     //线透明度
        strokeWeight: 6,      //线宽
        //strokeStyle: "solid"  //线样式
    });

    var passedPolyline = new AMap.Polyline({
        map: map,
        // path: lineArr,
        strokeColor: "#AF5",  //线颜色
        // strokeOpacity: 1,     //线透明度
        strokeWeight: 4,      //线宽
        //strokeStyle: "solid"  //线样式
    });


    marker.on('moving', function (e) {
        passedPolyline.setPath(e.passedPath);
    });

    map.setFitView();

    //车辆移动速度
    function startAnimation () {
        marker.moveAlong(lineArr, 300);
    }

    function pauseAnimation () {
        marker.pauseMove();
    }

    function resumeAnimation () {
        marker.resumeMove();
    }

    function stopAnimation () {
        marker.stopMove();
    }
</script>
</body>
</html>